﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.IO;
using DataAccessEntLib;

public partial class Notes_NTS_DocSearch : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
    {
        NTSList.RequestDataSet += new Notes_UserControls_NTS_Notes_List.ReBindDataSet(UC_RequestDataSet);
        if (!IsPostBack)
        {
            NTSList.dsDocs = AdvancedSearch();
        }

        Label lblEmpty = NTSList.FindControl("lblEmptyMessage") as Label;
        lblEmpty.Text = "Sorry no Document Found. Try searching with some other Criteria";
    }



    DataSet UC_RequestDataSet(object sender)
    {
        return AdvancedSearch();
    }
    protected DataSet AdvancedSearch()
    {
        System.Text.StringBuilder sbSearchFor = new System.Text.StringBuilder();
        sbSearchFor.Append("Showing Results for ");
        Notes.NotesDB _objNotesDB = new Notes.NotesDB();
        if (Session["DocName"] != null)
        {
            _objNotesDB.Title = Session["DocName"].ToString();
            sbSearchFor.Append("'" + _objNotesDB.Title + "'");

        }
        if (Session["StreamID"] != null)
        {
            _objNotesDB.StreamID = Convert.ToInt16(Session["StreamID"]);
            if (!string.IsNullOrEmpty(_objNotesDB.FileName))
                sbSearchFor.Append(" in ");
            sbSearchFor.Append("'" + Convert.ToString(Session["StreamName"]) + "'");
        }
        if (Session["SubjectID"] != null)
        {
            _objNotesDB.SubjectID = Convert.ToInt16(Session["SubjectID"]);
            if (!string.IsNullOrEmpty(_objNotesDB.FileName) || _objNotesDB.StreamID > 0)
                sbSearchFor.Append(" in ");
            sbSearchFor.Append("'" + Convert.ToString(Session["SubjectName"]) + "'");
        }
        if (Session["DocTypeID"] != null)
        {
            _objNotesDB.DocTypeID = Convert.ToInt16(Session["DocTypeID"]);

            if (!string.IsNullOrEmpty(_objNotesDB.FileName) || _objNotesDB.StreamID > 0 || _objNotesDB.SubjectID > 0)
                sbSearchFor.Append(" in ");
            sbSearchFor.Append("'" + Convert.ToString(Session["DocTypeName"]) + "'");
        }  
        DataSet ds = new DataSet();
        ds = _objNotesDB.Select_SearchDocuments();
        lblTitle.Text = sbSearchFor.ToString();
        return ds;
    }
}